#include <stdio.h>
#include <sys/stat.h>
#include <time.h>

int main(int argc, char *argv[])
{
    struct tm *p;
    struct  stat statbuf;
    char *wday[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
    if (argc != 2) {
        printf("Usage: ./%s filename\n", argv[0]);
        exit(1);
    }
    if (stat(argv[1], &statbuf) < 0) {
        printf("stat error");
        exit(1);
    }     
    p = localtime(&statbuf.st_atime);
    printf("文件最后一次访问时间: %d-%d-%d %s %d:%d:%d\n", (1900 + p->tm_year), (1 + p->tm_mon), p->tm_mday, wday[p->tm_wday], p->tm_hour, p->tm_min, p->tm_sec);
}